﻿<?php
$serverip=$_POST['serverip'];
$port=$_POST['port'];
$streamname=$_POST['streamname'];
$streamname=translitIt($streamname);
$streamlink=$_POST['streamlink'];
$ordertarif=$_POST['tarif'];
$reencode=$_POST['reencode'];
if($reencode>0)
    $reencode=1;
switch($ordertarif)
{
    case 'Lite': $slots=50;$quality=64; break;
    case 'Lite+': $slots=100;$quality=64; break;
    case 'Medium': $slots=50;$quality=128; break;
    case 'Medium+': $slots=100;$quality=128; break;
    case 'Professional': $slots=50;$quality=192; break;
    case 'Professional+': $slots=100;$quality=192; break;
    default:
        $tarif_array=explode("(",$ordertarif);
        $tarif_name=$tarif_array[0];
        $slots_array=explode(" ",$tarif_name);
        $slots=$slots_array[1];
        $quality_array=explode(" ",$tarif_array[1]);
        $quality=$quality_array[0];
        break;
}
if(strpos($streamlink,'http://')===false)
{
  if(strlen($streamlink)>0)
  {
    $streamlink='http://'.$streamlink;
  }
  else
  {
    $streamlink='http://radioheart.ru';
  }
}

$url='http://'.$serverip.'/panel/usericesconf_create.php';
$postdata='username=user'.$port.'&port='.$port.'&streamname='.$streamname.'&streamlink='.$streamlink.'&reencode='.$reencode.'&quality='.$quality;
//echo $postdata;
$data= post_content($url,$postdata);
echo $data;
function post_content ($url,$postdata) {
  $uagent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";

  $ch = curl_init( $url );
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_ENCODING, "");
  curl_setopt($ch, CURLOPT_USERAGENT, $uagent);  // useragent
  curl_setopt($ch, CURLOPT_TIMEOUT, 120);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  $content = curl_exec( $ch );
  curl_close( $ch );
  return $content;
}
function translitIt($str)
{
    $tr = array(
        "А"=>"a","Б"=>"b","В"=>"v","Г"=>"g",
        "Д"=>"d","Е"=>"e","Ж"=>"j","З"=>"z","И"=>"i",
        "Й"=>"y","К"=>"k","Л"=>"l","М"=>"m","Н"=>"n",
        "О"=>"o","П"=>"p","Р"=>"r","С"=>"s","Т"=>"t",
        "У"=>"u","Ф"=>"f","Х"=>"h","Ц"=>"ts","Ч"=>"ch",
        "Ш"=>"sh","Щ"=>"sch","Ъ"=>"","Ы"=>"yi","Ь"=>"",
        "Э"=>"e","Ю"=>"yu","Я"=>"ya","а"=>"a","б"=>"b",
        "в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"j",
        "з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
        "м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
        "с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
        "ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"y",
        "ы"=>"yi","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya",
        " "=> "_", "."=> ""
    );
    return strtr($str,$tr);
}
?>